package com.zzq.guli.service.edu.controller.api;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zzq.guli.service.base.result.R;
import com.zzq.guli.service.edu.entity.*;
import com.zzq.guli.service.edu.service.ChapterService;
import com.zzq.guli.service.edu.service.CourseService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;


//@CrossOrigin
@RequestMapping("api/edu/course")
@RestController
public class ApiCourseController {

    @Autowired
    CourseService courseService;




    @GetMapping("list/{page}/{limit}")
    public R getCourseList(@PathVariable Long page,
                           @PathVariable Long limit,
                           CourseQuery courseQuery){

        Page<CourseVo> courseVoList= courseService.selectPage(page,limit,courseQuery);

        return R.ok().data("courseList",courseVoList);

    }


    @GetMapping("getCourseById/{courseId}")
    public R getCourseById(@PathVariable String courseId){
        Course byId = courseService.getById(courseId);
        return R.ok().data("courseInfo",byId);

    }


    @GetMapping("getCourseInfo")
    public R getCourseInfo(@RequestBody WebCourseQuery webCourseQuery){

        List<Course> courseList=courseService.getCourseList(webCourseQuery);

        return R.ok().data("courseList",courseList);

    }

    @Autowired
    ChapterService chapterService;

    @ApiOperation("根据ID查询课程")
    @GetMapping("get/{courseId}")
    public R getById(
            @ApiParam(value = "课程ID", required = true)
            @PathVariable String courseId){

        //查询课程信息和讲师信息
        WebCourseVo webCourseVo = courseService.selectWebCourseVoById(courseId);

        //查询当前课程的章节信息
        List<ChapterVo> chapterVoList = chapterService.getNestedList(courseId);

        return R.ok().data("course", webCourseVo).data("chapterVoList", chapterVoList);
    }
}
